package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.Travel;
import cn.wolfcode.luowowo.article.domain.TravelContent;
import cn.wolfcode.luowowo.article.query.TravelQuery;
import cn.wolfcode.luowowo.article.service.ITravelService;
import cn.wolfcode.luowowo.common.util.JsonResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("travel")
public class TravelController {

    @Reference
    private ITravelService travelService;


    /**
     * 游记列表显示
     * @param qo
     * @param model
     * @return
     */
    @RequestMapping("list")
    public String list(@ModelAttribute("qo") TravelQuery qo, Model model) {
        PageInfo<Travel> pageInfo = travelService.queryForListFromBackStage(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "travel/list";
    }

    /**
     * 改变游记状态
     * @return
     */
    @RequestMapping("changeState")
    @ResponseBody
    public Object changeState(Long id,int state){
        travelService.updateState(id, state);
        return JsonResult.SUCCESS;
    }

    /**
     * 查看游记内容
     * @return
     */
    @RequestMapping("look")
    @ResponseBody
    public Travel check(Long id){
        TravelContent content = travelService.getContent(id);
        Travel travel = travelService.get(id);
        travel.setTravelContent(content);
        return travel;
    }

}
